Imports System.Data.OleDb
Imports System.Data.OracleClient
Imports System.IO


Namespace persistent

    Public Class DataEngine
        Private Shared ConnStr As String = GlobalVar.OraConnStr

        Public Shared Function ExecuteDataTable(ByVal command As OracleCommand, Optional ByVal directSql As Boolean = 0) As DataTable
            Dim connection As New OracleConnection(ConnStr)
            Dim dataAdapter As New OracleDataAdapter(command)
            Dim dataTable As New DataTable
            Dim dataSet As New DataSet

            command.Connection = connection

            If Not (directSql) Then
                command.CommandType = CommandType.StoredProcedure
            End If

            Try
                connection.Open()
                dataAdapter.Fill(dataSet)
                dataTable = dataSet.Tables(0)
            Catch ex As Exception
            Finally
                connection.Close()
                dataSet.Dispose()
            End Try

            Return dataTable
        End Function

        Public Shared Function ExecuteNonQuery(ByVal command As OracleCommand)
            Dim connection As New OracleConnection(ConnStr)
            command.Connection = connection
            command.CommandType = CommandType.StoredProcedure

            Try
                connection.Open()
                command.ExecuteNonQuery()
            Catch ex As Exception
            Finally
                connection.Close()
            End Try
        End Function

        Public Shared Function ExecuteScalar(ByVal command As OracleCommand) As Object
            Dim connection As New OracleConnection(ConnStr)
            Dim result As Object
            command.Connection = connection

            Try
                connection.Open()
                result = command.ExecuteScalar()
            Catch ex As Exception
            Finally
                connection.Close()
            End Try

            Return result
        End Function

        Public Shared Function ExecuteDataReader(ByVal command As OracleCommand) As OracleDataReader
            Dim connection As New OracleConnection(ConnStr)
            Dim dataReader As OracleDataReader
            command.Connection = connection

            Try
                connection.Open()
                dataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
            Catch ex As Exception
            End Try

            Return dataReader
        End Function

    End Class
End Namespace